package com.yq.socket1.day1.v4;


import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import javax.sound.midi.Soundbank;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @author 3307235355@qq.com
 * @description
 * @since 2022/07/01 10:51
 */
public class Client {
    public static void main(String[] args) throws IOException {


        Socket socket = new Socket("127.0.0.1",8888);
        // Socket socket = new Socket("192.168.13.75",8888);

        FileInputStream in = new FileInputStream("3.jpg");

        OutputStream out = socket.getOutputStream();

        byte[] bytes = new byte[1024];
        int readCount;
        while ((readCount=in.read(bytes))!=-1){
            out.write(bytes,0,readCount);
        }
        socket.shutdownOutput();

        //接收消息
        InputStream inputStream = socket.getInputStream();
        byte[] bytes1 = new byte[1024];
        int read = inputStream.read(bytes1);
        String s = new String(bytes1, 0, read);
        System.out.println(s);


        in.close();
        socket.close();
    }
}
